<?php
$prefix = 'level';
?>
<script>
function load_page(){
	$('#content').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
	$.get(
		'<?=$prefix?>_ajax.php',
		function(data){
			$('#content').html(data).hide().fadeIn('fast');;
			$('ul#icons li').hover(
				function() { $(this).addClass('ui-state-hover'); }, 
				function() { $(this).removeClass('ui-state-hover'); 
			});
			fgbutton();
	});
}
$(function(){
	load_page();
	$('#keyword').keyup(function() {
		$('#content').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
		$.post("<?=$prefix?>_ajax.php", { keyword: $("#keyword").val(),verify:1}, 
			function(data){
				$("#content").html(data);
			}
		);
	});
	
	$('#status').change(function(){
		$('#content').html('<img style=\'margin-top:100px;\' src=\'images/loading.gif\' align="absmiddle"/>'); 
		$.get('<?=$prefix?>_ajax.php',{status:$('#status').val()},
			function(data){
				$("#content").html(data);
			}
		);
	});
	
	$('#service').change(function(){
		$.get('<?=$prefix?>_ajax.php',{service:$('#service').val()},
			function(data){
				$("#content").html(data);
			}
		);
	});
	
	$('#type').change(function(){
		$.get('<?=$prefix?>_ajax.php',{type:$('#type').val()},
			function(data){
				$("#content").html(data);
			}
		);
	});
});

function active(id,status)
{
	$("#dialog_active").dialog({
		modal: true,
		buttons: {
			ตกลง: function() {
					$.get(
						'data_control.php',
						{id:id,status:status,action:'active',prefix:'<?=$prefix?>'},
						function(data){
							if(status == 'online'){
								$('#active'+id).html("<a onclick=\"active("+id+",'offline')\" href=\"javascript:void(0);\"><span style=\"color:black;\">offline</span></a>").hide().fadeIn('slow');
							}else{
								$('#active'+id).html("<a onclick=\"active("+id+",'online')\" href=\"javascript:void(0);\"><span style=\"color:green;\">online</span></a>").hide().fadeIn('slow');
							}
					});
					$( this ).dialog( "close" );
				},
			ยกเลิก:function() {
					$( this ).dialog( "close" );
				}
		}
	});
}
function Delete(id)
{
	$("#dialog2").dialog({
		modal: true,
		width:400,
		buttons: {
			ตกลง: function(){
				$.get('data_control.php',{id:id,action:'delete',prefix:'<?=$prefix?>'},function(data){load_page();});
				$( this ).dialog( "close" );
			},
			ยกเลิก:function(){
				$( this ).dialog( "close" );
			}
		}
	});
}
</script>
<div id="dialog_active" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการเปลี่ยนสถานะ?</p>
</div>
<div id="dialog2" title="ข้อความ"  style="display:none;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>ต้องการลบข้อมูล?</p>
</div>
<div id="member_dialog" title="ข้อมูลสมาชิก"  style="display:none;"></div>
<div id="tabs">
    <ul>
    	<li><a class="head_tab" style="padding-left:7px;" href="#tabs-1"><span class="ui-icon ui-icon-calendar" style="float:left;"></span>ระดับสมาชิก</a></li>
    </ul>
    <div id="tabs-1">
    	<table width="100%" border="1" align="center" cellpadding="3" cellspacing="0" style="border-collapse:collapse;" id="tbl_content">
          <tr class="ui-widget-header">
            <td width="58" align="center" >No.</td>
            <td width="522" align="center"   >ระดับ</td>
            <td width="573" align="center"   >คอมมิสชั่น</td>
            <td width="20" align="center" >แก้ไข</td>
          </tr>
           <?php
			$sql = "select * from tb_level";
			$qr = select($sql);
			$i=0;
			while($i<count($qr)){
				$rs = $qr[$i];
			?>
          <tr  bgcolor="<?=$bg?>"  onmouseout="this.className=''" onmouseover="this.className='ui-state-error'" id="list<?=$rs['id']?>">
            <td align="center" ><?=$limit_start+$i+1;?></td>
            <td align="center"><?=$rs['name']?></td>
            <td align="center"><?=$rs['price']?> %</td>
            <td align="center" valign="middle" width="20">
                <ul id="icons" class="ui-widget ui-helper-clearfix">
                    <li class="ui-state-default ui-corner-all" title="Edit" onclick="window.location='admin.php?page=<?=$prefix?>_add&id=<?=$rs['id']?>'"><span class="ui-icon ui-icon-wrench"></span></li>
                    
                   
              </ul>
            </td>
          </tr>
          <?php 
          $i++;
            }//end while//
          ?>
        </table>       
    </div>
</div>            